package com.example.newproject_overseas.Screen


import android.annotation.SuppressLint
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Cancel
import androidx.compose.material.icons.filled.Close
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalWindowInfo
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight.Companion.Bold
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import androidx.navigation.NavHostController
import com.example.newproject_overseas.R
import com.example.newproject_overseas.components.TopApp

@OptIn(ExperimentalComposeUiApi::class)
@SuppressLint("UnrememberedMutableState")
@Composable
fun ProductList(navController: NavHostController) {
    val screenWidth = with(LocalDensity.current) {
        LocalConfiguration.current.screenWidthDp.dp
    }
    val screenHeight = with(LocalDensity.current) {
        LocalConfiguration.current.screenHeightDp.dp
    }
    var showDialog by remember {
        mutableStateOf(false)
    }
    Column(
        modifier = Modifier
            .fillMaxSize()
            .background(color = Color(0XffF5F4F2))
    ) {
        if (showDialog) {
            Dialog(
                onDismissRequest = { showDialog = !showDialog },
                properties = DialogProperties(
                    usePlatformDefaultWidth = false
                )
            ) {
                Box(
                    modifier = Modifier
                        .padding(horizontal = 10.dp, vertical = 40.dp)
                        .fillMaxWidth()
                        .fillMaxHeight()


                ) {
                    Row(
                        modifier = Modifier
                            .fillMaxWidth()
                            .fillMaxHeight()
                    ) {
                        Image(
                            painter = painterResource(id = R.drawable.productlist_backimg),
                            contentScale = ContentScale.FillBounds,
                            contentDescription = null,
                            modifier = Modifier.fillMaxSize(),
                        )
                    }
                    Row(
                        modifier = Modifier
                            .padding(end = 5.dp, top = 5.dp)
                            .fillMaxWidth(),
                        horizontalArrangement = Arrangement.End
                    ) {
                        IconButton(
                            onClick = { showDialog = false },
                            modifier = Modifier.size(30.dp) // 设置图标大小
                        ) {
                            Icon(
                                imageVector = Icons.Default.Cancel,
                                contentDescription = null,
                                tint = Color.White
                            )
                        }
                    }
                    Row(modifier = Modifier.padding(start = 15.dp, top = 35.dp)) {
                        Text(
                            text = "You have applied for 1 loan products",
                            color = Color(0XFFFFFFFF),
                            fontSize = 17.5.sp
                        )
                    }
                    Row(modifier = Modifier.padding(start = 13.dp, top = 60.dp)) {
                        Text(
                            text = " The details of your loan products are as follows:",
                            color = Color(0XFFFFFFFF), fontSize = 15.sp
                        )
                    }
                    Row(modifier = Modifier.padding(start = 13.dp, top = 155.dp)) {
                        Text(
                            text = "Product NO:",
                            color = Color(0XFF252525), fontSize = 20.sp, fontWeight = Bold
                        )
                    }
                    Column(
                        modifier = Modifier
                            .padding(start = 0.dp, top = 195.dp)
                            .width(screenWidth)
                            .height(300.dp)
                            .padding(horizontal = 20.dp)
                            .background(color = Color(0XFFF1F1F1))
                    ) {
                        Row(modifier = Modifier.fillMaxWidth()) {
                            Column(
                                modifier = Modifier
                                    .weight(1f)
                                    .padding(top = 10.dp, start = 10.dp)
                            ) {
                                Text(
                                    text = "Loan products：",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    modifier = Modifier.padding(top = 20.dp)
                                )
                                Text(
                                    text = "Go Rupee",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    fontWeight = Bold
                                )
                                Text(
                                    text = "Loan amount：",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    modifier = Modifier.padding(top = 20.dp)
                                )
                                Text(
                                    text = "₹ 9000",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    fontWeight = Bold
                                )
                                Text(
                                    text = "GST：",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    modifier = Modifier.padding(top = 20.dp)
                                )
                                Text(
                                    text = "₹ 481",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    fontWeight = Bold
                                )

                            }
                            Column(modifier = Modifier.weight(1f)  .padding(top = 10.dp, start = 10.dp)) {
                                Text(
                                    text = "Term (Days):",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    modifier = Modifier.padding(top = 20.dp)
                                )
                                Text(
                                    text = "7 DAY",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    fontWeight = Bold
                                )
                                Text(
                                    text = "Daily interest rate:",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    modifier = Modifier.padding(top = 20.dp)
                                )
                                Text(
                                    text = "0.10%",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    fontWeight = Bold
                                )
                                Text(
                                    text = "Amount Received:",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    modifier = Modifier.padding(top = 20.dp)
                                )
                                Text(
                                    text = "₹ 5848",
                                    color = Color(0xff252525),
                                    fontSize = 15.sp,
                                    fontWeight = Bold
                                )
                            }

                        }
                        Column( modifier = Modifier.weight(1f).padding(start = 10.dp, top = 20.dp)) {
                            Text(
                                text = "Total interest and service fee：",
                                color = Color(0xff252525),
                                fontSize = 15.sp,
                                modifier = Modifier.padding(top = 20.dp)
                            )
                            Text(
                                text = "₹ 2671",
                                color = Color(0xff252525),
                                fontSize = 15.sp,
                                fontWeight = Bold
                            )
                        }

                    }
                    Box(
                        modifier = Modifier.fillMaxSize(),
                        contentAlignment = Alignment.BottomCenter
                    ) {
                        Button(
                            onClick = { showDialog=false},
                            colors = ButtonDefaults.buttonColors(
                                containerColor = Color(0xffFFCC00),
                                contentColor = Color.White
                            ),
                            modifier = Modifier.fillMaxWidth(),
                            shape = RoundedCornerShape(
                                topStart = 0.dp,
                                topEnd = 0.dp,
                                bottomStart = 15.dp,
                                bottomEnd = 15.dp
                            ),
                        ) {
                            Row(verticalAlignment = Alignment.CenterVertically) {
                                Text(
                                    text = "Confirm",
                                    modifier = Modifier.weight(1f),
                                    textAlign = TextAlign.Center,
                                    fontSize = 27.5.sp,
                                )
                            }
                        }
                    }


                }
            }


        }
        //导航栏
        TopApp(title = "Product List", navController = navController)

    }

    //底部按钮
    Box(
        modifier = Modifier.fillMaxSize(),
        contentAlignment = Alignment.BottomCenter
    ) {
        Button(
            onClick = { showDialog = true },
//                enabled = LoginViewodel.RadioButtonValue,
            colors = ButtonDefaults.buttonColors(
                containerColor = Color(0xffFFCC00),
                contentColor = Color.White
            ),
            modifier = Modifier.fillMaxWidth(),
            shape = RectangleShape //设置形状为矩形
        ) {
            Row(verticalAlignment = Alignment.CenterVertically) {
                Text(
                    text = "Submit",
                    modifier = Modifier.weight(1f),
                    textAlign = TextAlign.Center,
                    fontSize = 20.5.sp,
                )
            }
        }
    }
}




